import Vue from 'vue'
import Vuex from 'vuex'
import request from '@/common/api.js'
import quantity from './quantity'
import classify from './classify'
import app from './modules/app.js'
import code from '../uni_modules/uview-ui/libs/config/props/code'

Vue.use(Vuex)

//为了方便测试，此处用vuex做全局数据
const store = new Vuex.Store({
	state: {
		userInfo: {},
		isLogin: false,
		stock: {},
		token: '',
		// systemAppId:"",
		orderType: 1,
		scene: "",
		menuButton: {},
		orderId: '',
		remark: '',
		otherData: '',
		deskId: '',
		pageData: [], // 首页数据
		person: 0,
		address: {}, // 地址
		classType: 1,
		isIndex: false, // 首页跳转开台
		userBalance: {},
		showBoard: false, // 展示启动页广告
		popup: [{
			showPosition: []
		}, {
			showPosition: []
		}, {
			showPosition: []
		}]
	},
	mutations: {
		ChangeIndex(state, isIndex) {
			state.isIndex = isIndex
		},
		SET_PERSON(state, person) {
			state.person = person
		},
		// 首页数据
		SET_PAGEDATA(state, pageData) {
			state.pageData = pageData
		},
		SET_ORDERID(state, orderId) {
			state.orderId = orderId
		},
		SET_DESKID(state, deskId) {
			state.deskId = deskId
		},
		SET_ORDER_TYPE(state, orderType) {
			state.orderType = orderType
		},
		SET_ADDRESS(state, address) {
			state.address = address
		},
		SET_REMARK(state, remark) {
			state.remark = remark
		},
		SET_SCENE(state, scene) {
			state.scene = scene
			uni.setStorageSync('scene', scene)
			// state.scene = uni.getStorageSync('scene')
		},
		SET_STOCK(state, stock) {
			state.stock = stock // 店铺信息
			uni.setStorageSync('stock', stock)
		},
		SET_LOGIN(state, data) {
			state.isLogin = data.isLogin
			// state.stock = data.stock
			state.userInfo = data.userInfo
			state.systemAppId = data.systemAppId
			state.token = data.token
			state.otherData = data.otherData
			// uni.setStorageSync('stock', data.stock ) 
			uni.setStorageSync('otherData', data.otherData)
			uni.setStorageSync('token', data.token)
			uni.setStorageSync('userInfo', data.userInfo)
			uni.setStorageSync('systemAppId', data.systemAppId)
		},
		SET_USERBALANCE(state, payLoad) {
			state.userBalance = payLoad
		},
		LAY_OUT(state) {
			state.isLogin = false
			state.userInfo = {},
				state.token = '',
				uni.removeStorageSync('token')
			uni.removeStorageSync('userInfo')
		},
		SET_ADDRESS(state, payLoad) {
			state.address = payLoad
		},
		SET_CLASSTYPE(state, payLoad) {
			state.classType = payLoad
		},
		MenuButton_Client(state) {
			const res = uni.getMenuButtonBoundingClientRect()
			state.menuButton = res
		},
		ChangeShowBoard(state, payLoad) {
			state.showBoard = payLoad
		},
		// 弹窗数据
		SET_POPUP(state, payLoad) {
			state.popup = payLoad
		},
	},
	modules: {
		quantity,
		classify,
		app
	}
})

export default store